package cn.coisini.model.common.annotation;

import java.lang.annotation.*;

/**
 * @author xiangshaw
 * Description: redis缓存 自定义注解
 * @RedisCache(key = "'user:' + #userId", operation = RedisCache.OperationType.GET, timeout = 3600)
 * @RedisCache(key = "'userDto:' + #userDto.id", operation = RedisCache.OperationType.SAVE)
 * @RedisCache(key = "'userDto:' + #userDto.id", operation = RedisCache.OperationType.UPDATE, refresh = true)
 * @RedisCache(key = "'userDto:' + #id", operation = RedisCache.OperationType.DELETE)
 * 暂无使用
 */
// 指定注解信息
@Documented
// 指定注解作用位置
@Target({ElementType.METHOD})
// 指定注解生命周期 保留到运行时
@Retention(RetentionPolicy.RUNTIME)
public @interface RedisCache {
    // Redis key
    String key();

    // 操作类型（默认为查询）
    OperationType operation() default OperationType.GET;

    // 是否刷新缓存
    boolean refresh() default false;

    // 缓存时间，单位：秒，默认不设置过期时间
    long timeout() default -1;

    enum OperationType {
        GET, SAVE, DELETE, UPDATE
    }
}